package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
@Slf4j
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;


    @GetMapping
    @ApiOperation("查询所有护理项目数据")
    public ResponseResult<List<NursingPlanVo>> getNursingPlan() {
        return success(nursingPlanService.getNursingPlan());

    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目数据")
    public ResponseResult getbyid(Long id) {

        NursingPlanVo nursingPlanVo = nursingPlanService.getbyid(id);


        return success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation("根据id修改护理计划数据")
    public ResponseResult updateNursingPlan(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto) {
        log.info("根据id修改护理项目数据:{}", nursingPlanDto);
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理计划")
    public ResponseResult getNursingPlanStatus(
            @ApiParam(value = "护理计划名字", required = true) @PathVariable Long id,
            @ApiParam(value = "计划状态", required = true) @PathVariable Integer status) {
        nursingPlanService.getNursingPlanStatus(id,status);
        return success();


    }
    @ApiOperation("分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> searchNursingPlan(
            @ApiParam(value = "护理计划名称")
            @RequestParam(required = false) String name,
            @ApiParam(value = "护理计划状态")
            @RequestParam(required = false) Integer status,
            @ApiParam(value = "页码（默认为1）")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10）")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return ResponseResult.success(nursingPlanService.listByPage(name, status, pageNum, pageSize));
    }

}


